DEFINE BUFFER sct1 FOR sct_det.
DEFINE BUFFER pt1 FOR pt_mstr.
DEFINE BUFFER ptp1 FOR ptp_det.
DEFINE BUFFER sct2 FOR sct_det.
DEFINE BUFFER pt2 FOR pt_mstr.
DEFINE BUFFER ptp2 FOR ptp_det.


OUTPUT TO c:\qadguicli\doc\subcost.txt.
FOR EACH pts_ NO-LOCK,
    EACH ptp1 WHERE ptp1.ptp__chr01 = "C" AND ptp1.ptp_part = pts_part,
    EACH sct1 WHERE sct1.sct_part = ptp1.ptp_part AND sct1.sct_site = ptp1.ptp_site AND sct1.sct_sim = "standard", 
    EACH pt1  WHERE pt1.pt_part = ptp1.ptp_part,

    EACH ptp2 WHERE ptp2.ptp__chr01 = "C" AND ptp2.ptp_part = pts_sub_part,
    EACH sct2 WHERE sct2.sct_part = ptp2.ptp_part AND sct2.sct_site = ptp2.ptp_site AND sct2.sct_sim = "standard",
    EACH pt2  WHERE pt2.pt_part = ptp2.ptp_part
    AND abs(sct1.sct_mtl_tl - sct2.sct_mtl_tl) / sct1.sct_mtl_tl > 0.5:

    DISP pts_par (sct1.sct_mtl_tl - sct2.sct_mtl_tl) / sct1.sct_mtl_tl
         pts_part     sct1.sct_mtl_tl sct1.sct_site 
         pts_sub_part sct2.sct_mtl_tl sct2.sct_site
         pt1.pt_desc1 + pt1.pt_desc2 FORMAT "X(80)"
         pt2.pt_desc1 + pt2.pt_desc2 FORMAT "X(80)"
         pts_qty_per pts_userid WITH STREAM-IO WIDTH 320.
END.
